<template>
  <div class="category-page">
    <div class="container">
      <!-- 分类头部 -->
      <div class="category-header">
        <div class="category-info">
          <h1 class="category-title">{{ category.title }}</h1>
          <p class="category-desc">{{ category.description }}</p>
          <div class="category-stats">
            <div class="stat-item">
              <el-icon><Collection /></el-icon>
              <span>{{ category.courseCount }}门课程</span>
            </div>
            <div class="stat-item">
              <el-icon><User /></el-icon>
              <span>{{ category.studentCount }}名学员</span>
            </div>
            <div class="stat-item">
              <el-icon><Star /></el-icon>
              <span>{{ category.teacherCount }}位讲师</span>
            </div>
          </div>
        </div>
        <div class="category-banner">
          <img :src="category.banner" :alt="category.title" />
        </div>
      </div>

      <!-- 筛选栏 -->
      <div class="filter-bar">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-select v-model="filters.level" placeholder="难度等级">
              <el-option label="全部" value="" />
              <el-option label="入门" value="beginner" />
              <el-option label="中级" value="intermediate" />
              <el-option label="高级" value="advanced" />
            </el-select>
          </el-col>
          <el-col :span="6">
            <el-select v-model="filters.sort" placeholder="排序方式">
              <el-option label="最新发布" value="newest" />
              <el-option label="最多学习" value="popular" />
              <el-option label="评分最高" value="rating" />
            </el-select>
          </el-col>
          <el-col :span="12">
            <el-input
              v-model="filters.keyword"
              placeholder="搜索课程"
              :prefix-icon="Search"
              @keyup.enter="handleSearch"
            />
          </el-col>
        </el-row>
      </div>

      <!-- 课程列表 -->
      <div class="course-grid">
        <el-row :gutter="20">
          <el-col :span="6" v-for="course in courses" :key="course.id">
            <el-card class="course-card" @click="router.push(`/course/${course.id}`)">
              <img :src="course.cover" class="course-cover" />
              <h3 class="course-title">{{ course.title }}</h3>
              <p class="course-desc">{{ course.description }}</p>
              <div class="course-info">
                <span class="teacher">{{ course.teacher }}</span>
                <span class="students">{{ course.students }}人学习</span>
              </div>
              <div class="course-footer">
                <span class="price">¥{{ course.price }}</span>
                <el-button type="primary" size="small">立即学习</el-button>
              </div>
            </el-card>
          </el-col>
        </el-row>
      </div>

      <!-- 分页 -->
      <div class="pagination">
        <el-pagination
          v-model:current-page="currentPage"
          v-model:page-size="pageSize"
          :total="total"
          :page-sizes="[12, 24, 36, 48]"
          layout="total, sizes, prev, pager, next"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { Search, Collection, User, Star } from '@element-plus/icons-vue'

const router = useRouter()
const route = useRoute()

// 分类数据
const category = ref({
  id: 1,
  title: '前端开发',
  description: '从HTML/CSS基础到Vue.js、React等现代前端框架，系统学习前端开发技能',
  banner: 'https://picsum.photos/1200/300?random=1',
  courseCount: 128,
  studentCount: 25600,
  teacherCount: 32
})

// 筛选条件
const filters = reactive({
  level: '',
  sort: 'newest',
  keyword: ''
})

// 分页
const currentPage = ref(1)
const pageSize = ref(12)
const total = ref(100)

// 课程数据
const courses = ref([
  {
    id: 1,
    title: 'Vue.js 3.0 实战教程',
    description: '从入门到精通的Vue.js 3.0课程',
    cover: 'https://picsum.photos/300/200?random=1',
    teacher: '张老师',
    students: 1234,
    price: 299
  },
  // ... 更多课程数据
])

// 处理搜索
function handleSearch() {
  // TODO: 实现搜索逻辑
}

// 处理分页
function handleSizeChange(val) {
  pageSize.value = val
  // TODO: 重新加载数据
}

function handleCurrentChange(val) {
  currentPage.value = val
  // TODO: 重新加载数据
}

onMounted(() => {
  // TODO: 根据路由参数获取分类信息
  console.log('Category ID:', route.params.id)
})
</script>

<style scoped>
.category-page {
  padding: 20px;
  background-color: var(--bg-color);
  min-height: 100vh;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
}

.category-header {
  display: flex;
  gap: 40px;
  margin-bottom: 40px;
  background: white;
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.category-info {
  flex: 1;
}

.category-title {
  font-size: 28px;
  font-weight: bold;
  margin-bottom: 16px;
}

.category-desc {
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.6;
}

.category-stats {
  display: flex;
  gap: 40px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
}

.stat-item .el-icon {
  font-size: 20px;
  color: var(--primary-color);
}

.category-banner {
  width: 400px;
}

.category-banner img {
  width: 100%;
  border-radius: 8px;
}

.filter-bar {
  margin-bottom: 20px;
}

.course-grid {
  margin-bottom: 20px;
}

.course-card {
  margin-bottom: 20px;
  cursor: pointer;
  transition: all 0.3s;
}

.course-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.course-cover {
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-radius: 4px;
}

.course-title {
  margin: 12px 0;
  font-size: 16px;
  font-weight: bold;
}

.course-desc {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 12px;
  height: 40px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.course-info {
  display: flex;
  justify-content: space-between;
  color: var(--text-secondary);
  font-size: 12px;
  margin-bottom: 12px;
}

.course-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.price {
  color: var(--primary-color);
  font-size: 18px;
  font-weight: bold;
}

.pagination {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}
</style> 